package org.example.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.example.JavaBean.Emp;
import org.example.service.EmpService;
import org.example.util.JsonResult;
import org.example.util.ResultTool;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @Auther:Liu
 * @Testname:EmpController
 * @Date:2025/7/31 11:27
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/EmpAll")

public class EmpController {

    @Resource
    private EmpService empService;

    @GetMapping("/findall")
    public JsonResult findAll(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "10") int size) {
        return empService.findAll(page, size);
    }

    @GetMapping("/find_AllJob")
    public JsonResult findAllJob() {
        return empService.findAllJob();
    }

    @GetMapping("/find_AllMgr")
    public JsonResult findAllMgr() {
        return empService.findAllMgr();
    }

    @GetMapping("/find_ename_times")
    public JsonResult findEnameExists(String ename) {
        return empService.findEnameCount(ename);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody Emp emp) {
        return empService.save(emp);
    }

    @DeleteMapping("/delete")
    public JsonResult remove(int id) {
        return empService.removeById(id);
    }

    @DeleteMapping("/remove_batch")
    public JsonResult removeBath(String ids) {
        log.info("ids:{}", ids);
        return empService.removeByBatch(ids);
    }

    @PutMapping("/update")
    public JsonResult update(@RequestBody Emp emp) {
        return empService.update(emp);
    }

    @PostMapping("/search")
    public JsonResult findCascade( Emp emp, int page, int size) {
        return empService.findCascade(emp,page,size);
    }
}
